package com.itheima.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.itheima.mapper.ProductMapper;
import com.itheima.pojo.Brand;
import com.itheima.pojo.PageBean;
import com.itheima.pojo.Product;
import com.itheima.pojo.ProductQuery;
import com.itheima.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * TODO
 *
 * @Author mr.wu
 * @Data #{DATE} #{TIME}
 */
@Service
public class ProductServiceImpl implements ProductService {

    @Autowired
    private ProductMapper productMapper;
    @Override
    public PageBean getPage(ProductQuery productQuery) {

            PageHelper.startPage(productQuery.getPageNum(),productQuery.getPageSize() );
            List<Product> list = productMapper.getPage(productQuery);
            Page<Product> page = (Page) list;
            return new PageBean(page.getTotal(),page.getResult());

    }

    @Override
    public List<Brand> getBrandList() {
        List<Brand> list = productMapper.getBrandList();
        return list;
    }
}
